function showCenterDeviceSearch() {
	window.location.href = "showCenterDeviceSearch.do";
}

function ajaxFindCenterDeviceSearchList(currentPage,pageSize) {
	$.ajax({
		type : "post",
		url : "ajaxCenterDeviceSearchList.do",
		data : {
			deviceNum : $("#deviceNum").val(),
			currentPage:currentPage,
			pageSize:pageSize,
		},
		success : function(msg) {
			$("#listCenterDeviceBox").html(msg);
		}
	});
}

function ajaxShowCenterDeviceEdit(id){
	$.ajax({
		type:"post",
		url:"ajaxShowCenterDeviceEdit.do",
		data:{centerDeviceId:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 740,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons: [
				          {
				        	  text: "保存",
				        	  click: function() {
				        		  ajaxSaveCenterDevice(this);
				        	  }
				          },
				          {
				        	  text: "关闭",
				        	  click: function() {
				        		  $(this).dialog( "close" );
				        	  }
				          }
				          ]
			});
		}
	});
}


function ajaxSaveCenterDevice(objDialog) {
	centerDeviceValidate();
	if ($("#frmCenterDevice").valid()) {
		$(objDialog).dialog("close");
		var options ={
				type: "post",
				url : "ajaxSaveCenterDevice.do",
				success: function (msg) {
					clearInput("#sltCenterDevice");
					showMessageDialog("保存中心设备信息","中心设备信息保存成功。",null,dialogType.info);
					ajaxFindCenterDeviceSearchList();
				}
		};
		$("#frmCenterDevice").ajaxSubmit(options);
	}
}

function ajaxShowCenterDeviceView(id){
	$.ajax({
		type:"post",
		url:"ajaxShowCenterDeviceView.do",
		data:{centerDeviceId:id},
		success:function(msg){
			$("#dialog").html(msg);
			$("#dialog").dialog({
				autoOpen: true,
				width: 740,
				title:$(".dialogtitle").attr("title"),
				modal: true,
				buttons : [ {
					text : "关闭",
					click : function() {
						$(this).dialog("close");
					}
				} ]
			});
		}
	});
}

function ajaxDeleteCenterDeviceById(id) {
	var CenterDeviceIds="";
	var sltCD = $("#listCenterDeviceList tbody input:checked").length;
	if(id==null){
		$("#listCenterDeviceList tbody input:checked").each(function(){ 
			CenterDeviceIds += $(this).val()+";";
		});
		if(sltCD == 0){
			showMessageDialog("提示","请选择一行或多行",null,dialogType.info);
			return;
		}else{
			CenterDeviceIds = CenterDeviceIds.substring(0, CenterDeviceIds.length-1);
		} 
	}else{
		CenterDeviceIds=id;
		sltCD = 1;
	}
	if( CenterDeviceIds!=null){
		showMessageDialog("删除中心设备信息","确定要删除所选“"+sltCD+"”条中心设备信息记录吗？",
				function () {
			$.ajax({     
				type:"post",
				url:"ajaxDeleteCenterDeviceByIds.do",
				data:{CenterDeviceIds:CenterDeviceIds},
				success:function(msg){
					ajaxFindCenterDeviceSearchList();
					showMessageDialog("提示","中心设备信息删除成功",null,dialogType.info);
				}
			});
		}
		,dialogType.warning);
	}
}

function centerDeviceValidate(){
	$("#frmCenterDevice").validate({
		errorLabelContainer: $("#infoCenterDevice"),
		rules : {
			deviceName : {
				required :true				
			},
			deviceType : {
				required :true				
			},
			supervisorName : {
				required :true				
			},
			buyDate : {
				required :true				
			},
			deviceCode : {
				required :true				
			},
			ownedOrganization : {
				required :true				
			},
			deviceStatus : {
				required :true				
			},
			contactWay : {
				required :true				
			},
			location : {
				required :true				
			}
		},
		messages : {
			deviceName : {
				required :"请输入设备名称！"
			},
			deviceType : {
				required :"请选择设备类型！"
			},
			supervisorName : {
				required :"请输入负责人！"
			},
			buyDate : {
				required :"请输入购买日期！"
			},
			deviceCode : {
				required :"请输入设备编号！"
			},
			ownedOrganization : {
				required :"请选择所属单位！"
			},
			deviceStatus : {
				required :"请选择设备状态！"
			},
			contactWay : {
				required :"请输入联系方式！"
			},
			location : {
				required :"请输入所在位置！"
			}
		},
		success: function(label) {
			label.html("&nbsp;");
		}
	});
}